class Solution {
public:
    int getLongestPalindrome(string s)
    {
        int n = s.size();
        int ret = 0;
        int left, right = 0;

        for (int i = 0; i < n; i++)
        {
            left = i - 1, right = i + 1;
            while (left >= 0 && right < n && s[left] == s[right])
            {
                left--;
                right++;
            }
            ret = max(ret, right - left - 1);

            left = i, right = i + 1;
            while (left >= 0 && right < n && s[left] == s[right])
            {
                left--;
                right++;
            }
            ret = max(ret, right - left - 1);
        }
        return ret;
    }
};